package com.example.dellpc.myapplication;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TextView;

import com.example.utils.DataCleanManager;
import com.example.utils.StatusBarUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * Created by 刘智强 on 2016/9/12.
 * 关于缓存的计算和清楚
 */
public class CachDataActivity extends Activity {
    @ViewInject(R.id.tv_cachdata)
    private TextView tv_cachdata;
    @ViewInject(R.id.btn_clearcachdata)
    private Button btn_clear;

    private  String cach_data_size;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
// Translucent status bar
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// Translucent navigation bar
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        setContentView(R.layout.cachdata_activity);
        StatusBarUtils.setTranslucent(this);
        ViewUtils.inject(this);
        try {
           cach_data_size = DataCleanManager.getTotalCacheSize(getApplicationContext());
            tv_cachdata.setText(cach_data_size);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @OnClick(R.id.btn_clearcachdata)
    public void onClick(Button btn) {
        switch (btn.getId()) {
            case R.id.btn_clearcachdata:
                DataCleanManager.clearAllCache(getApplicationContext());
                try {
                    cach_data_size=DataCleanManager.getTotalCacheSize(getApplicationContext());
                    tv_cachdata.setText(cach_data_size);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;


            default:
        }

    }
}
